﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PiscoSourDominio;
using Dapper;

namespace PiscoSourSOAPServices.Persistencia
{

    public class OrdenDAO
    {
        public string InsertarOrdenes(Orden orden)
        {
            try
            {
                using (var sqlConnection = ConnectionFactory.GetConnection())
                {

                    sqlConnection.Open();
                    string sqlQuery = "INSERT INTO PSR_ORDEN(intOrden,intCantidad,vchObservacion,intCodPlato,intReserva) VALUES (@intOrden,@intCantidad,@vchObservacion,@intCodPlato,@intReserva)";
                    sqlConnection.Execute(sqlQuery,
                        new
                        {
                            intOrden = orden.intOrden,
                            intCantidad = orden.intCantidad,
                            vchObservacion = orden.vchObservacion,
                            intCodPlato = orden.intCodPlato,
                            intReserva = orden.intReserva
                        });

                    sqlConnection.Close();
                    return "";
                }
            }
            catch (Exception ex) 
            {
                return ex.Message;
            }
        }

        public string ActualizarOrdenes(Orden orden)
        {
            try
            {
                using (var sqlConnection = ConnectionFactory.GetConnection())
                {

                    sqlConnection.Open();
                    string sqlQuery = "UPDATE PSR_ORDEN SET intCantidad=@intCantidad, vchObservacion=@vchObservacion, intCodPlato=@intCodPlato, intReserva=@intReserva WHERE intOrden=@intOrden";
                    sqlConnection.Execute(sqlQuery,
                        new
                        {
                            intOrden = orden.intOrden,
                            intCantidad = orden.intCantidad,
                            vchObservacion = orden.vchObservacion,
                            intCodPlato = orden.intCodPlato,
                            intReserva = orden.intReserva
                        });

                    sqlConnection.Close();
                    return "";
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

        public string EliminarOrdenes(Orden orden)
        {
            try
            {
                using (var sqlConnection = ConnectionFactory.GetConnection())
                {

                    sqlConnection.Open();
                    string sqlQuery = "DELETE FROM PSR_ORDEN WHERE intOrden=@intOrden";
                    sqlConnection.Execute(sqlQuery,
                        new
                        {
                            intOrden = orden.intOrden
                        });

                    sqlConnection.Close();
                    return "";
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        
        public IEnumerable<Orden> ListarOrdenes()
        {
            return null;
        }
    }
}